<template>
	<view>
		<WxUserInfoModal v-model="show" @updated="updatedUserInfoEvent"></WxUserInfoModal>
	</view>
</template>

<script>
	import {
		wxLoginManager,
		AccountUserInfo,
		memberHasLoginManager,
		memberLogoutManager
	} from '@/api/login.js'

	import config from '@/common/config.js'
	import WxUserInfoModal from '@/uni_modules/tuniaoui-wx-user-info/components/tuniaoui-wx-user-info/tuniaoui-wx-user-info.vue'
	import {
		alUploadFile
	} from "@/uni_modules/qying-alUpload/js_sdk/alUpload";


	export default {
		components: {
			WxUserInfoModal,
		},
		props: {},
		data() {
			return {
				show: false,
				// 是否退出登录
				hasLogin: true,
			}
		},
		methods: {
			// 获取到的用户信息
			updatedUserInfoEvent(info) {
				console.log('获取到的用户信息', info)


				alUploadFile(info.avatar, true).then(res => {
					if (res.statusCode == 200) {
						info.avatar = res.file;
					}
					this.kuaijieLoginManager(info);
				});
			},

			// 主动去登录
			loginManager() {
				this.show = true;
				this.hasLogin = true;
			},
			// 主动去退出登录
			logoutManager() {
				this.show = true;
				var hasLoginStatus = memberHasLoginManager()
				if (hasLoginStatus === true) {
					this.hasLogin = false;
				} else {
					this.hasLogin = true;
				}
			},

			// 取消登录
			closeManager() {
				this.show = false;
				this.hasLogin = true;
			},

			// 快捷登录
			kuaijieLoginManager(info) {
				this.hasLogin = true;
				this.show = false;
				this.interfacewxLoginManager(info);
			},

			// 被动登录
			autoLoginManager() {
				this.hasLogin = true;
				var hasLogin = memberHasLoginManager()
				if (hasLogin === true) { // 表示用户登录状态
					// 3.获取用户数据
					var that = this;
					this.interfaceAccountUserInfo().then(userInfo => {
						// 1. 关闭弹层
						that.closeManager();
						// 2. 回抛数据
						that.$emit('actionEventManager', 'loginSuccess', userInfo);
					});
				}
			},
			// 微信一键登录
			interfacewxLoginManager(info) {
				// 1. 微信进行登录
				var that = this
				wxLoginManager().then(res => {
					// 微信登录成功
					if (res === true) {
						// 3.获取用户数据
						that.interfaceAccountUserInfo(info).then(userInfo => {
							// 1. 关闭弹层
							that.show = false;
							
							// 2. 回抛数据
							that.$emit('actionEventManager', 'loginSuccess', userInfo);
						});
					}
				})
			},

			////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


			// 接口获取用户信息
			interfaceAccountUserInfo(info) {
				var that = this;
				return new Promise(resolve => {
					AccountUserInfo(info).then(res => {
						resolve(res);
					})
				});
			},

			// 代理协议信息
			delegateOnChange() {
				this.delegatedChecked = !this.delegatedChecked
			},

			directToDelegateManager() {
				// 用户协议
				this.$refs.termofServiceSheet.open();
			},

			tuichudengluManager() {
				console.log('退出登录');
				var that = this;
				memberLogoutManager().then(res => {
					// 1. 关闭弹层
					that.closeManager();
					// 2. 回抛数据
					that.$emit('actionEventManager', 'logoutSuccess', '');
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	// 1. 主视图
	.content {
		height: 100vh;
		background-color: #f8fafd
	}

	.mine {
		max-height: 100vh;
	}

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}

	.tn-color-cat {
		color: #1D2541;
	}

	.tn-bg-cat {
		background-color: #1D2541;
	}


	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin: auto 5rpx;
			font-size: 40rpx;
			margin-right: 10rpx;
			flex-basis: 5%;
			width: 100rpx;
			position: absolute;
		}
	}

	/* 自定义导航栏内容 end */


	/* 顶部背景图 end */


	/* 用户头像 start */
	.logo-image {
		width: 110rpx;
		height: 110rpx;
		position: relative;
		overflow: hidden;
		border-radius: 50%;
	}

	.logo-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border: 8rpx solid rgba(255, 255, 255, 0.05);
		box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
		border-radius: 50%;
		overflow: hidden;
		// background-color: #FFFFFF;
	}

	/* 页面 start*/
	.about-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	.about {

		&__wrap {
			position: relative;
			z-index: 1;
			margin: 20rpx 30rpx;
		}
	}

	/* 页面 end*/

	/* 图标容器15 start */
	.icon15 {
		&__item {
			width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 100rpx;
				height: 100rpx;
				font-size: 60rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;


				}
			}
		}
	}

	/* 图标容器12 start */
	.tn-three {
		position: absolute;
		top: 50%;
		right: 50%;
		bottom: 50%;
		left: 50%;
		transform: translate(-38rpx, -16rpx) rotateX(30deg) rotateY(20deg) rotateZ(-30deg);
		text-shadow: -1rpx 2rpx 0 #f0f0f0, -2rpx 4rpx 0 #f0f0f0, -10rpx 20rpx 30rpx rgba(0, 0, 0, 0.2);
	}

	.icon20 {
		&__item {
			width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 100rpx;
				height: 100rpx;
				font-size: 60rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
					background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/icon_bg.png);
				}
			}
		}
	}



	.button-vip {
		width: 100%;
		height: 150rpx;
		border-radius: 15rpx;
		position: relative;
		z-index: 1;

		&::after {
			content: " ";
			position: absolute;
			z-index: -1;
			width: 100%;
			height: 100%;
			left: 0;
			bottom: 0;
			border-radius: inherit;
			opacity: 1;
			transform: scale(1, 1);
			background-size: 100% 100%;
			background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/icon_bg.png);
		}
	}


	/* 图标容器12 start */
	.icon12 {
		&__item {
			width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 15rpx;
				height: 15rpx;
				font-size: 50rpx;
				border-radius: 50%;
				margin-bottom: 38rpx;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;

				}
			}
		}
	}

	/* 图标容器1 start */
	.icon1 {
		&__item {
			// width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 40rpx;
				height: 40rpx;
				font-size: 40rpx;
				border-radius: 50%;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
					background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/icon_bg.png);
				}
			}
		}
	}

	/* 图标容器1 end */


	/* 顶部背景图 start */
	.top-backgroup {
		height: 450rpx;
		z-index: -1;

		.backgroud-image {
			width: 100%;
			height: 450rpx;
			// z-index: -1;
		}
	}

	/* 顶部背景图 end */

	.van_popup--bottom {
		position: fixed;
		// bottom: calc(var(--window-bottom) + 10rpx)
		bottom: 0;
		left: 0;
		z-index: 999;

		.login_box {
			width: 750rpx;
			background: #FFFFFF;
			border-top-left-radius: 40rpx;
			border-top-right-radius: 40rpx;
		}

		.login_title {
			font-size: 32rpx;
			font-weight: 500;
			color: rgba(0, 0, 0, 1);
			line-height: 32px;
			padding-top: 54rpx;
			margin: 0 36rpx;
			display: flex;
			justify-content: space-between;
		}

		.login_mode {
			padding: 160rpx 0;
		}

		.login_btn {
			width: 550rpx;
			height: 70rpx;
			line-height: 70rpx;
			/* #ifdef MP-ALIPAY */
			background: #0793de;
			/* #endif */
			/* #ifdef MP-WEIXIN */
			background: #0793de;
			/* #endif */
			border-radius: 50rpx;
			font-size: 32rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			margin: 30px auto;
			text-align: center;
		}

		.login_text {
			width: 400rpx;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 32rpx;
			margin: 20px auto;
			text-align: center;
			font-family: PingFangSC-Regular, PingFang SC;
		}
	}
</style>